﻿using FireStarterModeller.BO;
using Habanero.BO;
using Habanero.BO.ClassDefinition;

namespace FireStarterModeller.Logic
{
    public class SolutionLoader
    {
        public static void LoadAllSolutionBusinessObjects(DMSolution dmSolution)
        {
            //This should not be necessary we had an issue with ensuring that all relationship were loaded.

            BusinessObjectCollection<DMPropertyType> propertyTypes = dmSolution.PropertyTypes;
//            propertyTypes.Refresh();
            BusinessObjectCollection<UIControlMapperType> controlMapperTypes = dmSolution.UIControlMapperTypes;
//            controlMapperTypes.Refresh();
            BusinessObjectCollection<UIControlType> types = dmSolution.UIControlTypes;
//            types.Refresh();
            BusinessObjectCollection<UIControlType> uiControlTypes = types;
            BusinessObjectCollection<UITypeDefinition> types1 = dmSolution.UIFilterControlTypes;
//            types1.Refresh();
            BusinessObjectCollection<UITypeDefinition> filterControlTypes = types1;
            BusinessObjectCollection<UIGridColumnControlType> types2 = dmSolution.UIGridColumnControlTypes;
//            types2.Refresh();
            BusinessObjectCollection<UIGridColumnControlType> gridColumnControlTypes = types2;

            BusinessObjectCollection<DMAssembly> modules = dmSolution.Assemblies;
//            modules.Refresh();
            foreach (DMAssembly assembly in modules)
            {
                BusinessObjectCollection<DMClass> entities = assembly.Classes;
//                entities.Refresh();
                foreach (DMClass dmClass in entities)
                {
                    {
                        BusinessObjectCollection<DMProperty> properties = dmClass.Properties;
//                        properties.Refresh();
                        foreach (DMProperty property in properties)
                        {
                            DMPropRule rule = property.DefaultPropRule;
                            if (rule == null) continue;
                            //                        BusinessObjectCollection<DMPropRule> rules = property.PropRules;
                            BusinessObjectCollection<DMPropRuleParameter> propRuleParameters = rule.PropRuleParameters;
                        }
                        BusinessObjectCollection<DMRelationship> relationships = dmClass.OwnerRelationships;
//                        relationships.Refresh();
                        foreach (DMRelationship relationship in relationships)
                        {
                            BusinessObjectCollection<DMRelationshipProperty> relationshipProperties = relationship.RelationshipProperties;
//                            relationshipProperties.Refresh();
                            foreach (DMRelationshipProperty property in relationshipProperties)
                            {
                                IDMProperty property1 = property.OwnerProperty;
                                IDMProperty relatedProperty = property.RelatedProperty;
                            }
                        }
                        
                        BusinessObjectCollection<DMUniqueConstraint> constraints = dmClass.UniqueConstraints;
//                        constraints.Refresh();
                        foreach (DMUniqueConstraint constraint in constraints)
                        {
                            BusinessObjectCollection<DMUniqueConstraintProperty> uniqueConstraintProperties = constraint.UniqueConstraintProperties;
//                            uniqueConstraintProperties.Refresh();
                            foreach (DMUniqueConstraintProperty property in uniqueConstraintProperties)
                            {
                                DMProperty property1 = property.Property;
                            }
                        }
                        DMObjectIdentity identity = dmClass.ObjectIdentity;
                        BusinessObjectCollection<UIView> views = dmClass.UIViews;
//                        views.Refresh();
                        foreach (UIView view in views)
                        {
                            UIGridInfo gridInfo = view.UIGridInfo;
                            if (gridInfo != null)
                            {
                                BusinessObjectCollection<UIGridColumnInfo> columns1 = gridInfo.UIColumns;
                                //                            columns1.Refresh();
                                BusinessObjectCollection<UIGridColumnInfo> columns = columns1;
                                foreach (UIGridColumnInfo info in columns)
                                {
                                    BusinessObjectCollection<UIParameter> parameters1 = info.UIParameters;
                                    //                                parameters1.Refresh();
                                    BusinessObjectCollection<UIParameter> parameters = parameters1;
                                }

                                UIGridFilter filter = gridInfo.UIGridFilter;
                                if (filter != null)
                                {
                                    BusinessObjectCollection<UIGridFilterProp> props = filter.UIGridFilterProps;
                                    //                                props.Refresh();
                                    foreach (UIGridFilterProp prop in props)
                                    {
                                        BusinessObjectCollection<UIParameter> parameters1 = prop.UIParameters;
                                        //                                    parameters1.Refresh();
                                        BusinessObjectCollection<UIParameter> parameters = parameters1;
                                    }
                                }
                            }
                            UIFormInfo uiFormInfo = view.UIFormInfo;
                            if (uiFormInfo != null)
                            {
                                BusinessObjectCollection<UITab> tabs = uiFormInfo.UITabs;
//                            tabs.Refresh();
                                foreach (UITab tab in tabs)
                                {
                                    BusinessObjectCollection<UIColumnLayout> layouts = tab.UIColumnLayouts;
//                                layouts.Refresh();
                                    foreach (UIColumnLayout columnLayout in layouts)
                                    {
                                        BusinessObjectCollection<UIField> fields = columnLayout.UIFields;
//                                    fields.Refresh();
                                        foreach (UIField field in fields)
                                        {
                                            BusinessObjectCollection<UIParameter> parameters1 = field.UIParameters;
//                                        parameters1.Refresh();
                                            BusinessObjectCollection<UIParameter> parameters = parameters1;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}